package com.slz3.business.module.configManagement.conFeedback.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.configManagement.conFeedback.domain.ConFeedback;
import com.slz3.business.module.configManagement.conFeedback.domain.ConFeedbackFactory;
import com.slz3.business.module.configManagement.conFeedback.steward.ConFeedbackSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class ConFeedbackServiceImpl implements ConFeedbackService {
    @Override
    public ConFeedback save(ConFeedback conFeedback) {
        return Repositorys.conFeedback.save(ConFeedbackFactory.initBaseFields(conFeedback));
    }
    @Override
    public Page<ConFeedback> page(MultiValueMap<String, String> params) {
        Page<ConFeedback> conFeedbackPage = Repositorys.conFeedback.findAll(
                ConFeedbackSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return conFeedbackPage;
    }


    @Override
    public ConFeedback modify(ConFeedback conFeedbackNew) {
        return Repositorys.conFeedback.saveAndFlush(ConFeedbackFactory.initBaseFields(conFeedbackNew));
    }

    @Override
    public Optional<ConFeedback> single(UUID uuid) {
        return Repositorys.conFeedback.findById(uuid);
    }

    @Override
    public List<ConFeedback> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.conFeedback.findAllById(uuids);
    }

    @Override
    public List<ConFeedback> delete(List<ConFeedback> conFeedbackList) {
        conFeedbackList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            ConFeedbackFactory.initBaseFields(item);
        });
        return Services.conFeedbackTransactional.batchModify(conFeedbackList);
    }

}
